{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c3c62cf0",
   "metadata": {},
   "source": [
    "* 2022/10/18/week09\n",
    "* python课堂笔记"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f0622b2",
   "metadata": {},
   "source": [
    "# 本周知识点"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3bdf3278",
   "metadata": {},
   "source": [
    "> 1. while循环  \n",
    "> 2. 购物车练习  \n",
    "> 3.元组_集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ab722369",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿 0\n",
      "你是风儿 1\n",
      "你是风儿 2\n",
      "你是风儿 3\n",
      "你是风儿 4\n",
      "你是风儿 5\n",
      "你是风儿 6\n",
      "你是风儿 7\n",
      "你是风儿 8\n",
      "你是风儿 9\n",
      "你是风儿 10\n",
      "你是风儿 11\n",
      "你是风儿 12\n",
      "你是风儿 13\n",
      "你是风儿 14\n",
      "你是风儿 15\n",
      "你是风儿 16\n",
      "你是风儿 17\n",
      "你是风儿 18\n",
      "你是风儿 19\n",
      "你是风儿 20\n",
      "你是风儿 21\n",
      "你是风儿 22\n",
      "你是风儿 23\n",
      "你是风儿 24\n",
      "你是风儿 25\n",
      "你是风儿 26\n",
      "你是风儿 27\n",
      "你是风儿 28\n",
      "你是风儿 29\n",
      "你是风儿 30\n",
      "你是风儿 31\n",
      "你是风儿 32\n",
      "你是风儿 33\n",
      "你是风儿 34\n",
      "你是风儿 35\n",
      "你是风儿 36\n",
      "你是风儿 37\n",
      "你是风儿 38\n",
      "你是风儿 39\n",
      "你是风儿 40\n",
      "你是风儿 41\n",
      "你是风儿 42\n",
      "你是风儿 43\n",
      "你是风儿 44\n",
      "你是风儿 45\n",
      "你是风儿 46\n",
      "你是风儿 47\n",
      "你是风儿 48\n",
      "你是风儿 49\n",
      "你是风儿 50\n",
      "你是风儿 51\n",
      "你是风儿 52\n",
      "你是风儿 53\n",
      "你是风儿 54\n",
      "你是风儿 55\n",
      "你是风儿 56\n",
      "你是风儿 57\n",
      "你是风儿 58\n",
      "你是风儿 59\n",
      "你是风儿 60\n",
      "你是风儿 61\n",
      "你是风儿 62\n",
      "你是风儿 63\n",
      "你是风儿 64\n",
      "你是风儿 65\n",
      "你是风儿 66\n",
      "你是风儿 67\n",
      "你是风儿 68\n",
      "你是风儿 69\n",
      "你是风儿 70\n",
      "你是风儿 71\n",
      "你是风儿 72\n",
      "你是风儿 73\n",
      "你是风儿 74\n",
      "你是风儿 75\n",
      "你是风儿 76\n",
      "你是风儿 77\n",
      "你是风儿 78\n",
      "你是风儿 79\n",
      "你是风儿 80\n",
      "你是风儿 81\n",
      "你是风儿 82\n",
      "你是风儿 83\n",
      "你是风儿 84\n",
      "你是风儿 85\n",
      "你是风儿 86\n",
      "你是风儿 87\n",
      "你是风儿 88\n",
      "你是风儿 89\n",
      "你是风儿 90\n",
      "你是风儿 91\n",
      "你是风儿 92\n",
      "你是风儿 93\n",
      "你是风儿 94\n",
      "你是风儿 95\n",
      "你是风儿 96\n",
      "你是风儿 97\n",
      "你是风儿 98\n",
      "你是风儿 99\n"
     ]
    }
   ],
   "source": [
    "# while True 可以实现 for + range的方法\n",
    "# while True 一般用于不确定的循环次数或者无数次循环操作\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"你是风儿\",count)\n",
    "    count +=1\n",
    "    if count == 100:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2bfc4aa4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import getpass\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "count = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fd2887d7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card54\n"
     ]
    }
   ],
   "source": [
    "# 猜数字小游戏： 0<n<100,5次机会猜数字，每次猜完出题人提示你猜的有点大或者有点小\n",
    "\n",
    "hide_card = int(input(\"hide_card\")) #出题人\n",
    "count = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e6a88ba3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card:········\n",
      "游戏开始\n",
      "guess_digit33\n",
      "往大的想想\n",
      "guess_digit21\n",
      "往大的想想\n",
      "guess_digit56\n",
      "往小的想想\n",
      "guess_digit77\n",
      "往小的想想\n",
      "guess_digit56\n",
      "往小的想想\n",
      "猜这么多次都不对,你个笨蛋!\n",
      "正确答案：54\n"
     ]
    }
   ],
   "source": [
    "import getpass\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "count = 0\n",
    "if hide_card <100 and hide_card >0:\n",
    "        print(\"游戏开始\")\n",
    "        while True:\n",
    "            if count <5:\n",
    "                guess_digit = int(input(\"guess_digit\")) #玩游戏的人\n",
    "                if guess_digit == hide_card:\n",
    "                    print(\"yes,you got it.\")\n",
    "                    break\n",
    "                elif guess_digit > hide_card:\n",
    "                    print(\"往小的想想\")\n",
    "                else:\n",
    "                    print(\"往大的想想\")\n",
    "                count = count+1\n",
    "            else:\n",
    "                print(\"猜这么多次都不对,你个笨蛋!\")\n",
    "                print(\"正确答案：%s\"%(hide_card))\n",
    "                break\n",
    "else:\n",
    "    print(\"请输入数字在0-99之间。不要耍赖！\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b938ce9",
   "metadata": {},
   "source": [
    "# 购物车"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3fe70a0d",
   "metadata": {},
   "source": [
    "# 购物车程序项目：\n",
    "\n",
    ">1、运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "\n",
    ">2、让用户输入商品编号进行商品的购买。\n",
    "\n",
    ">3、用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "\n",
    ">4、用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8a377832",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (3111827161.py, line 32)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [5]\u001b[1;36m\u001b[0m\n\u001b[1;33m    elif user_choice == \"q\":\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 1、运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "good_list = [\n",
    "    [\"蜜桃四季春\",6],\n",
    "    [\"柠檬四季春\",4],\n",
    "    [\"草莓奶盖\",10],\n",
    "    [\"杨枝甘露\",12],\n",
    "]\n",
    "# 数据存放，列表的增加(append)\n",
    "shopping_list = []\n",
    "Alipay = int(input(\"请输入余额：\"))\n",
    "\n",
    "while True:\n",
    "    print(\"----蜜雪冰城商品列表----\")\n",
    "    for i in range(4):\n",
    "        print(i,good_list[i][0],str(good_list[i][1])+\"元\")\n",
    "    # 2.让用户输入商品编号进行商品的购买\n",
    "    user_choice = int(input(\"请输入商品编号:\"))\n",
    "    # 3、用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "    #3.1 用户输入商品序号(数值)\n",
    "    if user_choice.isdigit:\n",
    "        user_choice = int(user_choice)\n",
    "    good_list[user_choice][1]\n",
    "    if Alipay > good_list[int(user_choice)][1]:\n",
    "        #余额够\n",
    "        Alipay = Alipay - good_list[int(user_choice)][1] #更新用户余额\n",
    "        shopping_list.append(good_list[user_choice])\n",
    "        print(\"购买成功，请等待制作,您的余额还有：%s元\"%(Alipay))\n",
    "    else:\n",
    "        #余额不够\n",
    "        print(\"余额不足\")\n",
    "    #3.2用户输入其他\n",
    "    elif user_choice == \"q\":\n",
    "        print(\"感谢您的购买，欢迎下次光临\")\n",
    "        print(\"您的购物车\",shopping_list)\n",
    "        print(\"您的余额还有：\",Alipay)\n",
    "        break\n",
    "    else:\n",
    "        print(\"您输入的商品不存在\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ad9e7d1e",
   "metadata": {},
   "outputs": [],
   "source": [
    "good_list = [\n",
    "    [\"蜜桃四季春\",6],\n",
    "    [\"柠檬四季春\",4],\n",
    "    [\"草莓奶盖\",10],\n",
    "    [\"杨枝甘露\",12],\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27c9afab",
   "metadata": {},
   "outputs": [],
   "source": [
    "good_list[0][1]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
